using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.Tests
{
	[TestFixture]
	public class DummyTest
	{
		#region SetUp

		[SetUp]
		public void SetUp()
		{
		}

		#endregion

		#region TearDown

		[TearDown]
		public void TearDown()
		{
		}

		#endregion

		#region Tests

		[Test(Description = "")]
		[Explicit]
		public void Test_METHODNAME()
		{
			var documentOriginal = new XmlDocument();
			documentOriginal.LoadXml(File.ReadAllText(@"D:\Projects\WOW\WowSvn\trunk\src\Acceptance\Outfitter\OutFitter.xml"));

			var documentModified = new XmlDocument();
			documentModified.LoadXml(File.ReadAllText(@"D:\Temp\Outfitter\OutFitter.xml"));


			using (var form = new Form())
			{
				var treeView1 = new TreeView();
				var treeView2 = new TreeView();
				form.Controls.Add(treeView1);
				form.Controls.Add(treeView2);
				form.Size = new Size(500, 500);
				treeView1.Size = new Size(250, 250);
				treeView2.Size = new Size(250, 250);
				treeView1.Dock = DockStyle.Left;
				//treeView1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
				treeView2.Dock = DockStyle.Left;
				AddNodes(treeView1, documentOriginal);
				AddNodes(treeView2, documentModified);
				form.ShowDialog();
			}
		}

		/// <summary>
		/// Adds the nodes.
		/// </summary>
		/// <param name="treeView">The tree view.</param>
		/// <param name="document">The document.</param>
		private static void AddNodes(TreeView treeView, XmlDocument document)
		{
			try
			{
				treeView.BeginUpdate();
				var treeNode = treeView.Nodes.Add("Controls");

				XmlNodeList nodes = document.DocumentElement.ChildNodes;

				RecurseNodes(treeNode, nodes);
			}
			finally
			{
				treeView.CollapseAll();
				treeView.EndUpdate();
			}
		}

		/// <summary>
		/// Recurses the nodes.
		/// </summary>
		/// <param name="treeNode">The tree node.</param>
		/// <param name="nodes">The nodes.</param>
		private static void RecurseNodes(TreeNode treeNode, XmlNodeList nodes)
		{
			if (nodes == null) return;

			for (int index = 0; index < nodes.Count; index++)
			{
				XmlNode xmlNode = nodes[index];
				string name = xmlNode.Name;
				if (xmlNode.Attributes != null)
				{
					var nameAttribute =
						xmlNode.Attributes.OfType<XmlAttribute>().Where(attr => attr != null && attr.Name == "name").FirstOrDefault();
					if (nameAttribute != null)
						name = nameAttribute.Value;
				}
				var node = treeNode.Nodes.Add(name);
				RecurseNodes(node, xmlNode.ChildNodes);
			}
		}

		#endregion
	}
}